#include "rtk.h"

#define MAXSIZE 2048

//测试
int main()
{
    //字符串
    char base[MAXSIZE]="";      //一个历元的基准站观测值
    char rover[MAXSIZE]="";     //一个历元的流动站观测值
    char nav[MAXSIZE]="";       //一颗卫星的星历
    char pos[MAXSIZE]="-2436619.400,4091816.900,4228873.900";       //基准站坐标
    char result[MAXSIZE]="";    //定位结果
    char result_single[MAXSIZE]="";    //定位结果

    //打开数据文件
    char BasObs[] = "F:\\datadecode\\RTK0712\\data\\addd_B001"; //文件名
    char RovObs[] = "F:\\datadecode\\RTK0712\\data\\addd_M002"; //文件名
    char Nav[] = "F:\\datadecode\\RTK0712\\data\\addd_NAV"; //文件名
    FILE *fp_BasObs,*fp_RovObs,*fp_Nav;
    if((fp_BasObs = fopen(BasObs,"r")) == NULL)
    {
        printf("error!");
        return -1;
    }
    if((fp_RovObs = fopen(RovObs,"r")) == NULL)
    {
        printf("error!");
        return -1;
    }
    if((fp_Nav = fopen(Nav,"r")) == NULL)
    {
        printf("error!");
        return -1;
    }

    //初始化
    RTK rtk(pos);
    RTK single;
    //读取星历
    while (!feof(fp_Nav))
    {
        fgets(nav,2000,fp_Nav);  //读取一行
        rtk.GetNav(nav);
        single.GetNav(nav);
    }
    fclose(fp_Nav);

    //读取观测值
    while (!feof(fp_RovObs))
    {
        fgets(rover,2000,fp_RovObs);  //读取一行流动站

        if(feof(fp_BasObs)) break;    //如果没有基准站观测值则退出
        fgets(base,2000,fp_BasObs);   //读取一行基准站
        rtk.GetObs(base,rover);       //观测值解码
        single.GetRovObs(rover);
        rtk.RtkPos(result);           //RTK定位解算
        single.SinglePos(result_single);
    }
    fclose(fp_BasObs);
    fclose(fp_RovObs);

    return 0;
}
